<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="基金名">
              <a-input placeholder="请输入基金名" v-model="queryParam.fundname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="状态">
              <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="order_status"/>
            </a-form-item>
          </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="基金code">
                <a-input placeholder="请输入基金code" v-model="queryParam.fcode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="订单号">
                <a-input placeholder="请输入订单号" v-model="queryParam.orderNum"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="第三方订单号">
                <a-input placeholder="请输入第三方订单号" v-model="queryParam.payNum"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="支付方式">
                <j-dict-select-tag placeholder="请选择支付方式" v-model="queryParam.payType" dictCode="pay_type"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('基金申购订单表')">导出</a-button>
      <!-- 高级查询区域 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
            <a-divider type="vertical" />
             <a @click="handleSupplement(record)" style='color: red' v-if='record.status==3'>补单</a>
        </span>

      </a-table>
    </div>

    <userhome-order-modal ref="modalForm" @ok="modalFormOk"></userhome-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import UserhomeOrderModal from './modules/UserhomeOrderModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { getAction, postAction } from '@api/manage'

  export default {
    name: 'UserhomeOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      UserhomeOrderModal
    },
    data () {
      return {
        description: '基金订单表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'基金名',
            align:"center",
            dataIndex: 'fundname'
          },
          {
            title:'基金code',
            align:"center",
            dataIndex: 'fcode'
          },
          {
            title:'用户',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'交易类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'金额',
            align:"center",
            dataIndex: 'amount'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'订单号',
            align:"center",
            dataIndex: 'orderNum'
          },
          {
            title:'第三方订单号',
            align:"center",
            dataIndex: 'payNum'
          },
          {
            title:'支付方式',
            align:"center",
            dataIndex: 'payType_dictText'
          },
          {
            title:'签署合同的图片',
            align:"center",
            dataIndex: 'agreeUrl',
            scopedSlots: { customRender: 'imgSlot' }
          },

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/fund/userhomeOrder/list",
          supplement: "/fund/userhomeOrder/supplement",
          exportXlsUrl: "/fund/userhomeOrder/exportXls",
          importExcelUrl: "fund/userhomeOrder/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
        this.queryParam.type=1;
        this.loadData();
      },
      loadData(arg) {
        debugger
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        if(this.queryParam.type==null) {
          return false;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      handleSupplement(record)
      {
        if(record.status!=3)
        {
          this.$message.error("该订单无法补单")
          return false;
        }
        let params=
          {
            orderNum:record.orderNum
          };
        postAction(this.url.supplement, params).then((res) => {
          if (res.success) {
            this.loadData()
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'fundName',text:'基金名',dictCode:''})
        fieldList.push({type:'int',value:'type',text:'交易类型(1申购 2赎回 3提现)',dictCode:'order_type'})
        fieldList.push({type:'BigDecimal',value:'amount',text:'金额',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态(0 进行中 1成功 2过期 3异常 4失败)',dictCode:'order_status'})
        fieldList.push({type:'string',value:'orderNum',text:'订单号',dictCode:''})
        fieldList.push({type:'string',value:'payNum',text:'第三方订单号',dictCode:''})
        fieldList.push({type:'string',value:'relationId',text:'申购id',dictCode:''})
        fieldList.push({type:'int',value:'payType',text:'支付方式 1 支付宝 2微信 3 网银 4银盛支付宝 5银盛微信 6银盛网银',dictCode:'pay_type'})
        fieldList.push({type:'string',value:'fundCode',text:'基金code',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>